﻿Public Class frmProveedorBuscador

    Private Sub frmProveedorBuscador_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgProveedor.AutoGenerateColumns = False
        CargarProveedores()
    End Sub

    Private _codProveedor As Integer = 0

    Public Property codProveedor() As Integer
        Get
            Return _codProveedor
        End Get
        Set(ByVal value As Integer)
            _codProveedor = value
        End Set
    End Property

    Private _Proveedor As String = ""

    Public Property ProveedorDesc() As String
        Get
            Return _Proveedor
        End Get
        Set(ByVal value As String)
            _Proveedor = value
        End Set
    End Property

    Dim controller As New ControllerSigeco.controller_compras()

    Private Sub CargarProveedores()

        Dim dt As New DataTable
        dt = controller.get_Proveedores_All(oiml.dbConn, 0, txtProveedor.Text, txtruc.Text, True)
        dgProveedor.DataSource = dt

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub seleccionar_proveedor()
        Try
            If dgProveedor.SelectedRows.Count > 0 Then

                codProveedor = dgProveedor.SelectedRows(0).Cells(0).Value
                ProveedorDesc = dgProveedor.SelectedRows(0).Cells(1).Value
                Me.Close()

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarProveedores()
    End Sub

    Private Sub txtProveedor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtProveedor.KeyDown, txtruc.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarProveedores()

        End If
    End Sub

    Private Sub dgProveedor_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgProveedor.DoubleClick
        seleccionar_proveedor()
    End Sub

    Private Sub dgProveedor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgProveedor.KeyDown
        If e.KeyCode = Keys.Enter Then
            seleccionar_proveedor()
        End If

    End Sub


End Class